import java.io.IOException;
import java.io.PrintWriter;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class SendMail {

    static void main (String args[]) {

        String from = "wli";
	String to   = "aaindex@yahoo.com";
        String subject = "app test";
        String content = "mailcontent";

        try {

            //Acquire our JavaMail session object
            Context initCtx = new InitialContext();
            Context envCtx  = (Context) initCtx.lookup("java:comp/env");
	    Session session = (Session) envCtx.lookup("mail/Session");

            // Prepare our mail message
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            InternetAddress dests[] = new InternetAddress[] { new InternetAddress(to) };
            message.setRecipients(Message.RecipientType.TO, dests);
            message.setSubject(subject);
            message.setContent(content, "text/plain");

            // Send our mail message
            Transport.send(message);

            System.out.println("Message successfully sent!");

        } catch (Throwable t) {
	    
            System.out.println("ENCOUNTERED EXCEPTION:  " + t);
	}

	try {
	    CheckMail t = new CheckMail();
	    int i = t.checkMyMail("192.168.1.104", "wli", "NguyeLi5788");
	    if (i==0) {
		System.out.println("No mail waiting.");
	    }
	    else {
		System.out.println
		    ("There " + (i==1?"is " :"are ") + i +
		     " message" +(i==1?"":"s")+ " waiting.");
	    }
	}
	catch (Exception e) {
	    e.printStackTrace();
	}
    }

}








